//
//  TMCommentCell.swift
//  GZWeibo007
//
//  Created by denjunjie1 on 15/12/24.
//  Copyright © 2015年 Apple. All rights reserved
//

import UIKit

import SDWebImage

class TMCommentCell: UITableViewCell {
    
    var cellhright : CGFloat = 0.0
    var comments : TMComments? {
        
        didSet{
            
            commentLabel.text = comments?.text
            
            //赋值给top的模型
            topView.comments = comments
            layoutIfNeeded()
            self.cellhright = CGRectGetMaxY(self.commentLabel.frame) + 10
        }
        
    }
    
    
    
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        prepareUI()
        
    }
    
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    
    private func prepareUI(){
        
        contentView.addSubview(topView)
        contentView.addSubview(commentLabel)
        
        
        commentLabel.translatesAutoresizingMaskIntoConstraints = false
        
        topView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: contentView, size: CGSize(width: UIScreen.mainScreen().bounds.width, height: 53))
        
        
        commentLabel.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: topView, size: nil, offset: CGPoint(x: 50, y: 0))
        
        contentView.addConstraint(NSLayoutConstraint(item: commentLabel, attribute: NSLayoutAttribute.Right, relatedBy: NSLayoutRelation.Equal, toItem: contentView, attribute: NSLayoutAttribute.Right, multiplier: 1, constant: -8))
        //
        //        contentView.addConstraint(NSLayoutConstraint(item: commentLabel, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: contentView, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 0))
        
        
        
    }
    
    
    private lazy var topView: TMTopView = TMTopView()
    
    
    
    lazy var commentLabel : UILabel = {
        
        let label = UILabel()
        
        label.font = UIFont.systemFontOfSize(14)
        
        label.numberOfLines = 0
        
        label.sizeToFit()
        
        return label
    }()
    
}
